package com.example.weatherdemo.server;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author junoppa
 */
public class WeatherData {

    public static String getCityWeather(String city) throws Exception {
        String url = "http://wthrcdn.etouch.cn/weather_mini?city=" + city;
        OkHttpClient okHttpClient = new OkHttpClient();
        final Request request = new Request.Builder()
                .url(url)
                .build();
        final Call call = okHttpClient.newCall(request);
        Response response = call.execute();
        String ret =  response.body().string();
        System.out.println("查询天气数据：" + ret);
        return ret;
    }

    public static void main(String[] args) throws Exception{
        long startTime = System.currentTimeMillis();
        for (int i=0;i<50;i++){
            getCityWeather("北京");
        }
        for (int i=0;i<40;i++){
            getCityWeather("上海");
        }
        for (int i=0;i<30;i++){
            getCityWeather("广州");
        }
        for (int i=0;i<20;i++){
            getCityWeather("深圳");
        }
        for (int i=0;i<10;i++){
            getCityWeather("南京");
        }
        long endTime2 = System.currentTimeMillis();
        System.out.println("----costTime: "+(endTime2 - startTime) +" 毫秒");
    }
}
